package com.cheng.spider.dao;

import com.cheng.spider.dao.entity.Item;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class ItemDao {

    private static final String SQL = "insert into item  " +
            "(title, url, img_url, classify1, classify2) " +
            "values " +
            "(?, ?, ?, ?, ?);";

    public static int insertItem(Item item) {
        int count = 0;
        Connection connection = null;
        PreparedStatement ps = null;
        try {
            connection = JdbcUtils.getConnection();
            ps = connection.prepareStatement(SQL);
            ps.setString(1, item.getTitle());
            ps.setString(2, item.getUrl());
            ps.setString(3, item.getImgUrl());
            ps.setString(4, item.getClassify1());
            ps.setString(5, item.getClassify2());
            count = ps.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JdbcUtils.close(connection, ps);
        }
        return count;
    }

}
